﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CrystalDecisions.CrystalReports.Engine;

public partial class Web_ProductReport : System.Web.UI.Page
{
    string button = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        Session["current"] = "Product Detail Report";//current page
        if (Session["user"] != null)//check user
        {
            string user = Session["user"].ToString();
            if (user == "viewer")
            {
                Response.Redirect("index.aspx");
            }

        }
        else
        {
            Response.Redirect("index.aspx");
        }

        if (IsPostBack == true)//check selected radiobutton
       
             button =Session["button"].ToString();
        {
            if (button == "1")
            {
                button4();
                button4();
            }
            else
                 if (button == "2")
            {
                button5();
                button5();
            }
            else
                      if (button == "3")
            {
                button6();
                button6();
            }
            
        }

        ASPxLabel6.Visible = false;
        ASPxLabel7.Visible = false;
        ASPxLabel8.Visible = false;
        DropDownList1.Visible = false;
        DropDownList2.Visible = false;
        DropDownList3.Visible = false;
    }

    #region move to correct radio button
    protected void ASPxRadioButton4_CheckedChanged(object sender, EventArgs e)
    {
        try
        {
            if (ASPxRadioButton4.Checked)
            {
                ASPxLabel6.Visible = true;
                DropDownList1.Visible = true;
                Session["button"] = "1";
            }
        }
        catch
        {
            Response.Redirect("404.aspx");
        }
    }
    protected void ASPxRadioButton5_CheckedChanged(object sender, EventArgs e)
    {
        try
        {
        if (ASPxRadioButton5.Checked)
        {
            ASPxLabel7.Visible = true;
            DropDownList2.Visible = true;
            Session["button"] = "2";
        }
        }
        catch
        {
            Response.Redirect("404.aspx");
        }
    }
    protected void ASPxRadioButton6_CheckedChanged(object sender, EventArgs e)
    {
        try
        {
        if (ASPxRadioButton6.Checked)
        {
            ASPxLabel8.Visible = true;
            DropDownList3.Visible = true;
            Session["button"] = "3";
        }
        }
        catch
        {
            Response.Redirect("404.aspx");
        }
    }
    protected void ASPxButton1_Click(object sender, EventArgs e)
    {
        try
        {
        if (ASPxRadioButton4.Checked)
        {
            button4();
        }
        else if (ASPxRadioButton5.Checked)
        {
            button5();
        }
        else if (ASPxRadioButton6.Checked)
        {
            button6();
        }
        }
        catch
        {
            Response.Redirect("404.aspx");
        }
        
    }
    #endregion

    #region button actions
    public Boolean button4()
    {
        try
        {
            ReportDocument reportdocument = new ReportDocument();
            reportdocument.Load(Server.MapPath("Bin/productbycat.rpt"));
            reportdocument.SetDatabaseLogon("bestlifeuser", "Pass@123");
            reportdocument.SetParameterValue("cat", DropDownList1.SelectedValue);
            CrystalReportViewer1.ReportSource = reportdocument;
            CrystalReportViewer1.ParameterFieldInfo.Clear();
            Session["button"] = "1";
            return true;
        }
        catch
        {
            Response.Redirect("404.aspx");
            return false;
        }
    }
    public Boolean button5()
    {
        try
        {
            ReportDocument reportdocument = new ReportDocument();
            reportdocument.Load(Server.MapPath("Bin/productbysubcat.rpt"));
            reportdocument.SetDatabaseLogon("bestlifeuser", "Pass@123");
            reportdocument.SetParameterValue("subcat", DropDownList2.SelectedValue);
            CrystalReportViewer1.ReportSource = reportdocument;
            CrystalReportViewer1.ParameterFieldInfo.Clear();
            Session["button"] = "2";
            return true;
        }
        catch
        {
            Response.Redirect("404.aspx");
            return false;
        }
        
    }
    public Boolean button6()
    {
        try
        {
            ReportDocument reportdocument = new ReportDocument();
            reportdocument.Load(Server.MapPath("Bin/productbysupplier.rpt"));
            reportdocument.SetDatabaseLogon("bestlifeuser", "Pass@123");
            reportdocument.SetParameterValue("sup", DropDownList3.SelectedValue);
            CrystalReportViewer1.ReportSource = reportdocument;
            CrystalReportViewer1.ParameterFieldInfo.Clear();
            Session["button"] = "3";
            return true;
        }
        catch
        {
            Response.Redirect("404.aspx");
            return false;
        }
    }
    #endregion

}